package com.jia.file.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jia.file.entity.File;
import com.jia.file.mapper.FileMapper;
import com.jia.file.service.FileService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements FileService {

    @Override
    public Map<String, Object> getPageList(long pageNum, long pageSize) {
        Map<String, Object> maps = new HashMap<>();
        Page<File> page = new Page<>(pageNum,pageSize);
        QueryWrapper<File> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("gmt_create");

        IPage<File> filePage = baseMapper.selectPage(page, wrapper);
        List<File> records = filePage.getRecords();
        long size = filePage.getSize();
        long current = filePage.getCurrent();
        long total = filePage.getTotal();

        maps.put("records",records);
        maps.put("current",current);
        maps.put("size",size);
        maps.put("total",total);
        maps.put("code",0);
        return maps;
    }
}
